package com.crm.controller.system;

import com.crm.dto.RolePageDTO;
import com.crm.pojo.Role;
import com.crm.result.PageResult;
import com.crm.result.Result;
import com.crm.service.system.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    /**
     * 查询角色列表
     *
     * @param rolePageDTO
     * @return
     */
    @GetMapping("list")
    public Result rolePageQuery(RolePageDTO rolePageDTO) {
        PageResult pageResult = roleService.list(rolePageDTO);
        return Result.commonSuccess(pageResult);
    }

    /**
     * 根据id查询角色
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        Role role = roleService.getByRoleId(id);
        return Result.success(role);
    }

    /**
     * 删除角色
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public Result deleteById(@PathVariable List<Long> ids){
        roleService.deletById(ids);
        return Result.success();
    }

    /**
     * 新增角色
     * @param role
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Role role){
        roleService.add(role);
        return Result.success();
    }

    /**
     * 更改状态
     * @return
     */
    @PutMapping("/changeStatus")
    public Result changeStatus(@RequestBody Role role){
        roleService.changeStatus(role);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody Role role){
        roleService.update(role);
        return Result.success();
    }

}
